<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>指定函数只能执行一次</title>
</head>
<body>
    <h1>Hello, World!</h1>
    <script>
        function func() {
            console.log("output from func()")
        }

        function execute_once(fn) {
            // 定义状态标识符
            let status = true
            return function (params) {
                if (status) {
                    fn.apply(params)
                    status = !status
                }
            }
        }

        let once = execute_once(func)
        once()
        once()
        once()
    </script>
</body>
</html>